home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
FORTH
/
DRAW_FOL
/
ABOUT_DR.AWE
Wrap
Text File
|
1992-05-17
|
4KB
|
81 lines
Class Drawer is one way to support a window with scrollable contents.
There are many ways to do this, each with its advantages and disadvantages.
This technique will not be apropriate for all situations, but it was easy
to implement and is very general.
Also needed are the two supplied, and modified, files for the View and
Scroller classes. The View class was only slightly modified in that the
vscroll? and hscroll? instance variables were promoted from the Scroller
subclass to the View superclass. And the SetupDraw: method was modified.
The Scroller class and supporting Vscroll/Hscroll classes were fairly
heavily modified.
The idea is to provide a general technique for scrolling the contents of
a window when the contents is too big to fit. This will work for resizable
windows as well.
A brief explanation of the overall logic is as follows.
The view and scroller classes are set up basically as before, except the
ACTIONS x-arrays of the scrollbars are loaded with CFAs that reference the
value thisCtl. ThisCtl, of course, will contain the current control object
(the one hit by the mouse), and from that control object will be known the
owning view object, since ^MYVIEW is an ivar of a control.
A new instance variable of class Scroller is DrawObject, which will contain
a Drawer object which must be passed upon Scroller instantiation. The Drawer
object must respond appropriately to a few messages. Note that late-binding
(or should I be calling it dynamic binding?) is heavily used throughout.
Anyway, since the key to drawing in a scrollable window is usually just drawing
relative to the control values, we pass the Scroller object itself to the
Drawer object when making a request for the Drawer object to draw itself.
See the sdraw: method in class Drawer. The scroller object will contain all
of the information we need to efficiently (or inefficiently) do our drawing.
Since the View subclass (which is what a Scroller is) will properly clip
the drawing, we can simply look at the control values and draw relative to
them. It will be more efficient, but certainly more complex, to also inspect
the size of the viewrect as well and limit drawing appropriately.
Class Drawer by itself will not do anything. It is intended to be subclassed,
and class DemoDrawer is an example. All that is really needed in a Drawer is a
proper response to the (late-bound) message reldraw: (relative draw), which
also passes the x and y location from which to base all drawing.
Note that a Drawer must contain other pertinent information needed for scrolling
such as the overall pixel size of the Drawer and how many pixels to scroll for
any given control hit situation. Defaults are provided, but these should be
set as needed.
DEMO
See the end of the file Drawer for an example of how to use a Drawer.
Try resizing the demo window. Note that the scrollbars will appropriately
activate and deactivate when the window is resized.
CAVEATS
This code hasn't really been thoroughly tested, but it may prove useful
as a starting point for more robust scrolling views.
This Scroller class is really not intended to be able to contain subviews.
For that matter, I'm not even sure that it will work as a subview, although
it probably should.
Also, both horizontal and vertical scrollbars are required. This could be
changed so that only one or the other is needed.
Since the control ranges and values are the actual pixel extents and offsets
of the Drawer, we are somewhat limited in drawing size. Another approach
might be to have the control range correspond to, for example, the number of
"cells" to be drawn where each cell could represent many pixels.
Also, another approach might simply offset the coordinate system itself based
on the control values.
Feedback/comments are welcome.
Doug Hoffman Compuserve 72310,1743
5/17/92